package com.yuyou.fn.provider.impl;

import com.github.wens.mybatisplus.plugins.Page;
import com.google.common.collect.Collections2;
import com.yuyou.fn.api.TeacherService;
import com.yuyou.fn.api.dto.OuterTeacherDto;
import com.yuyou.fn.api.dto.PageDto;
import com.yuyou.fn.api.dto.TeacherQueryParameterDto;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.portal.service.IOuterTeacherService;
import com.yuyou.fn.portal.vo.OuterTeacher;
import com.yuyou.fn.portal.vo.OuterTeacherQueryVo;

import javax.annotation.Resource;

public class ExposeTeacherServiceImpl implements TeacherService{

    @Resource
    private IOuterTeacherService outerTeacherService;

    @Override
    public PageDto<OuterTeacherDto> findTeacher(TeacherQueryParameterDto teacherQueryParameter, int pageNo, int pageSize) {
        OuterTeacherQueryVo outerTeacherQueryVo = new OuterTeacherQueryVo();
        BeanUtils.copyProperties(outerTeacherQueryVo,teacherQueryParameter);
        Page<OuterTeacher> page = outerTeacherService.findTeacher(outerTeacherQueryVo, pageNo, pageSize);
        return new PageDto<>(Collections2.transform(page.getRecords(),this::toOuterTeacherDto),pageNo,pageSize,page.getTotal());
    }

    @Override
    public OuterTeacherDto findTeacherDetail(Long teacherId) {
        return toOuterTeacherDto( outerTeacherService.findTeacherDetail(teacherId) );
    }

    private OuterTeacherDto toOuterTeacherDto(OuterTeacher teacher ) {
        OuterTeacherDto outerTeacherDto = new OuterTeacherDto() ;
        BeanUtils.copyProperties(outerTeacherDto,teacher);
        return outerTeacherDto;
    }
}
